package com.health.viewscontrols.settings;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.health.R;
import com.health.viewscontrols.NovaActivity;
import com.health.viewscontrols.NovaApplication;

/**
 * author : xiaoxin
 * date   : 2020/7/27 9:42
 * desc   :
 * update :
 */
public class WebViewActivity extends NovaActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        WebView webview = (WebView) findViewById(R.id.webview);
        WebSettings settings = webview.getSettings();
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        // 设置编码格式
        settings.setDefaultTextEncodingName("utf-8");
        // 支持js
        settings.setJavaScriptEnabled(true);//必须得设置不然js代码不能实现
        settings.setJavaScriptCanOpenWindowsAutomatically(true);//允许js弹出窗口
        webview.getSettings().setDomStorageEnabled(true);

        webview.loadUrl(url);


        //系统默认会通过手机浏览器打开网页，为了能够直接通过WebView显示网页，则必须设置
        settings.setBuiltInZoomControls(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
//        settings.setSavePassword(true);
//        settings.setSaveFormData(true);
//        settings.setJavaScriptEnabled(true);     // enable navigator.geolocation
        settings.setGeolocationEnabled(true);
        settings.setDomStorageEnabled(true);
        webview.requestFocus();
//        wv.setScrollBarStyle(0);
        webview.setWebChromeClient(new WebChromeClient());
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //使用WebView加载显示url
                view.loadUrl(url);
                //返回true
                return true;
            }
        });
    }

    @Override
    public void findViews() {

    }

    @Override
    public void setListeners() {

    }
}
